<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="crm.util.ParamUtil"%>
<%@page import="crm.model.Purchase"%>
<%@page import="crm.control.PurchaseControl"%>
<%@page import="java.util.*"%>
<%@page import="crm.control.EmployeesControl" %>
<%@page import="crm.model.Employees"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>跟单采购</title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="../../../resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="../../../resources/css/style.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="../../../resources/css/invalid.css" type="text/css" media="screen" />
<!--                       Javascripts                       -->
<!-- jQuery -->
<script type="text/javascript" src="../../../resources/scripts/jquery-1.3.2.min.js"></script>
<!-- jQuery Configuration -->
<script type="text/javascript" src="../../../resources/scripts/simpla.jquery.configuration.js"></script>
 <script type="text/javascript" src="../../../resources/js/WebCalendar.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="../../../resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="../../../resources/scripts/jquery.wysiwyg.js"></script>
<!-- jQuery Datepicker Plugin -->
<script type="text/javascript" src="../../../resources/scripts/jquery.datePicker.js"></script>
<script type="text/javascript" src="../../../resources/scripts/jquery.date.js"></script>
<script type="text/javascript" src="../../../resources/js/reinitIframe.js"></script>
<script type='text/javascript'>
window.onload=function(){
	var num=document.getElementById('num').value;
	setInterval(function(){
		new ReinitIframe('iadd');
		new ReinitIframe('iinformation');
		for(var i=1;i<=num;i++){
			var check = 'icheck' + i;
			var update = 'iupdate' + i;
			new ReinitIframe(check);
			new ReinitIframe(update);
		}
	},200);
}
</script>
<style type="text/css">
.hide{
    position: absolute;
    zoom: 0.001;
    -moz-transform: scale(0);
    -webkit-transform: scale(0);
    -o-transform: scale(0);
    transform: scale(0);
}
</style>
</head>
	<body>
	<%
			// System.out.println(recepit_id);
	 %>
	<%
	        request.setCharacterEncoding("UTF-8");
	        Employees cu=(Employees)session.getAttribute("user");
	        String recepit_id = ParamUtil.getString(request,"id","-1");
	        // System.out.println(recepit_id); 
			String goods_name = "";
			String person = "";
			String place = "";
			String seller = "";

			
			int type=ParamUtil.getInt(request,"type",1);
			if(type==1){
			goods_name = ParamUtil.getString(request,"goods_name",null);
			person = ParamUtil.getString(request,"person",null);
			place = ParamUtil.getString(request,"place",null);
			seller = ParamUtil.getString(request,"seller",null);
			recepit_id = ParamUtil.getString(request,"recepit_id",recepit_id);
			
			session.setAttribute("goods_name",goods_name);
			session.setAttribute("person",person);
			session.setAttribute("place",place);
			session.setAttribute("seller",seller);
			// session.setAttribute("recepit_id",seller);
			}else{
			goods_name = (String)session.getAttribute("goods_name");
			person = (String)session.getAttribute("person");
			place = (String)session.getAttribute("place");
			seller = (String)session.getAttribute("seller");
			// recepit_id = (String)session.getAttribute("recepit_id");
			}
	 %>
	 <div id="body-wrapper">
  <!-- Wrapper for the radial gradient background -->
  <div id="sidebar">
    <div id="sidebar-wrapper">
      <!-- Sidebar with logo and menu -->
      <h1 id="sidebar-title"><a href="#">Simpla Admin</a></h1>
      <!-- Logo (221px wide) -->
      <a href="#"><img id="logo" src="../../../resources/css/slice/notice.png" alt="Simpla Admin logo" /></a>
      <!-- Sidebar Profile links -->
      <div id="profile-links"><a href="#" title="Edit your profile"><%=EmployeesControl.getEmployeesName(cu.getId())%>,您好！</a><a href="#messages" rel="modal" title="3 Messages"></a><br />
        <br />
        <a href="#information" rel='modal' >修改个人信息</a> | <a href="../../login/logout.jsp" title="zhuxiao">注销</a> </div>
      <ul id="main-nav">
        <!-- Accordion Menu -->
        <li> <a href="#" class="nav-top-item">公司页面 </a>
          <ul>
	          <li><a href='../company/material/material_download.jsp'>资料 </a></li>
	          <li><a href='../company/notice/notice.jsp'>公告</a></li>
	          <li><a href='../company/salearea/salearea.jsp'>销售区域</a></li>
	          <li><a href='../company/saleskill/saleskill.jsp'>销售技巧</a></li>
	          <li><a href='../company/saletarget/saletarget.jsp'>销售目标</a></li>
          </ul>
         </li>
        <li> <a href="../recepit/show_all_recepits.jsp" class="nav-top-item current no-submenu">
          <!-- Add the class "current" to current menu item -->
           我的跟单</a>
          <!--ul>
            <li><a href="#">Write a new Article</a></li>
            <li><a class="current" href="#">Manage Articles</a></li>
            <li><a href="#">Manage Comments</a></li>
            <li><a href="#">Manage Categories</a></li>
          </ul-->
        </li>
        
        <li> <a href="../offer/show_all_offers.jsp" class="nav-top-item no-submenu">报价</a>      
        </li>
        <li> <a href="../bargain/show_all_bargains.jsp" class="nav-top-item no-submenu">合同</a>
        </li>
        <li> <a href="../schedule/schedule.jsp" class="nav-top-item no-submenu">日程管理</a>
        </li>
        <li> <a href="../customer/customer.jsp" class="nav-top-item no-submenu">我的客户</a>
        </li>
        <%
            if(cu.getPosition()!=1){
            	%>
            	<li> <a href="#" class="nav-top-item">统计</a>
		          <ul>
		            <li><a href="../../control/statistics/company_statistics.jsp">公司统计</a></li>
		            <li><a href="../../control/statistics/employees_statistics.jsp">员工统计</a></li>
		          </ul>
		        </li>
            	<li><a href="../employees/employees.jsp" class="nav-top-item no-submenu">员工管理</a></li>
            	<%
            }
        %>
      </ul>
    </div>
  </div>
  <div id="main-content">
  <form action="purchase.jsp?type=1?id=<%=recepit_id %>" method="post">
	 <div class="content-box-header">
	 <h3 style="cursor: s-resize;">搜索条件</h3>
	 </div>
	 <table border='1'>
	<tr>
	<td>物品名称</td>
	<td><input type="text" name="goods_name" value="<%if(goods_name!=null&&!goods_name.equals("")) out.print(goods_name);%>"/></td>
	<td>购买人</td>
	<td><input type="text" name="person" value="<%if(person!=null&&!person.equals("")) out.print(person);%>"/></td>
	<td>购买地</td>
	<td><input type="text" name="place" value="<%if(place!=null&&!place.equals("")) out.print(place);%>"/></td>
	<td>销售者</td>
	<td><input type="text" name="seller" value="<%if(seller!=null&&!seller.equals("")) out.print(seller);%>"/></td>
	<%if(recepit_id!=null&&Integer.parseInt(recepit_id)<=0){%>
	<td>是否与跟单有关</td>
	<td><input type="radio" value="-2" name="recepit_id"/>是
	<input type="radio" value="0" name="recepit_id"/>否
	<input type="radio" value="-1" name="recepit_id" checked/>全部</td>
	<%}%>
	<td><input class='button' type="submit" value="查询"/></td>
	</tr>
	</table>
	</form>
	
	
<form method="post">
<fieldset>
<div class="content-box-header">
<h3 style="cursor: s-resize;">搜索结果</h3>
</div>
			<table>
				<thead>
					<tr>
						<th>
							物品名称
						</th>
						<th>
							单价
						</th>
						<th>
							总支出
						</th>
						<th>
							购买人
						</th>
						<th>
							操作
						</th>
					</tr>
				</thead>
				<tbody>
					<%
						int pages = ParamUtil.getInt(request, "pages", 0);
						int rowsPerpage = ParamUtil.getInt(request, "pageSize", 10);
						int i=0;
						Collection purchase = PurchaseControl.searchPurchase(recepit_id,goods_name,person,place,seller,rowsPerpage,pages);
					    // System.out.println(recepit_id);
					    Iterator iterator = purchase.iterator();
					    while(iterator.hasNext()){
					    i++;
					    Purchase purchase2 = (Purchase)iterator.next();
					%>
					<tr>
						<td align="center"><%=purchase2.getGoods_name()%></td>
						
						<td align="center"><%=purchase2.getSingle_price()%></td>
						<td align="center"><%=purchase2.getSum_fee()%></td>
						<td align="center"><%=purchase2.getPerson()%></td>
						<td align="center">
						<a href='#message<%=i %>' rel="modal">查看</a>
						<a>|</a>
						<a href='#messages<%=i %>' rel="modal">修改</a>
						<a>|</a>
						<a href="purchase_delete.jsp?id=<%=purchase2.getId()%>" onclick='return confirm("确定要删除吗?")'>删除</a>
						</td>
					</tr>
					<div  class='hide' >
				        <div id='message<%=i %>'>
							<iframe id='icheck<%=i %>'style='width:368px; overflow:hidden;' scrolling='no' frameborder='0'  src='readme.jsp?id=<%=purchase2.getId()%>'></iframe>
						</div>
					</div>
					<div  class='hide' >
				        <div id='messages<%=i %>'>
							<iframe id='iupdate<%=i %>'style='width:368px; overflow:hidden;' scrolling='no' frameborder='0'  src='purchase_update.jsp?id=<%=purchase2.getId()%>'></iframe>
						</div>
					</div>
					<%
						}
					%>
					<input type='hidden' id='num' value='<%=i %>'/>
				</tbody>
			</table>
			<%
				out.println(PurchaseControl.pageInstance.getToolsMenu(pages));
			%>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='#add' rel='modal' class='button'>添加采购信息</a> 
				</fieldset>
			<div  class='hide' >
		        <div id='add'>
					<iframe id='iadd'style='width:368px; overflow:hidden;' scrolling='no' frameborder='0'  src='purchase_add.jsp?id=<%=recepit_id %>'></iframe>
				</div>
			</div>
			<div class='hide' >
	<div id='information'>
		<iframe id='iinformation' style='width:368px; overflow:hidden;' scrolling='no' frameborder='0' src='../employees/employees_update.jsp'></iframe>
	</div>
</div>
		</form>
		</div>
		</div>
	</body>
</html>